import XEUtils from "xe-utils";
import {
  createEditRender,
  createFormItemRender,
  defaultExactFilterMethod,
  getCellEditFilterProps,
  getFilterOns,
  getNativeOns,
  handleConfirmFilter
} from "../pluginUtils";
import {RendererMapOptions} from "vxe-table/types/v-x-e-table/renderer";

const value: RendererMapOptions = {
  renderDefault: createEditRender(),
  renderEdit: createEditRender(),
  renderFilter(h, renderOpts, params) {
    const {column} = params
    const {name, attrs} = renderOpts
    const nativeOn = getNativeOns(renderOpts, params)
    return [
      h('div', {
        class: 'vxe-table--filter-element-wrapper'
      }, column.filters.map((option, oIndex) => {
        const optionValue = option.data
        return h(name, {
          key: oIndex,
          attrs,
          props: getCellEditFilterProps(renderOpts, params, optionValue),
          on: getFilterOns(renderOpts, params, option, () => {
            // 处理 change 事件相关逻辑
            handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
          }),
          nativeOn
        })
      }))
    ]
  },
  defaultFilterMethod: defaultExactFilterMethod,
  renderItem: createFormItemRender(),
  renderItemContent: createFormItemRender()
}
export default value
